package com.nirvana.flatbuffers;


/**
 * Copyright (c) 2022 Aoshu.Co.Ltd. All rights reserved.
 *
 * @author :    zhouqichun
 * @create :    2025/11/14 10:13
 * @description :
 **/
public class WeightsWapperResolver implements IResolve {
    @Override
    public boolean canResolve(String propertyType) {
        return "WeightsWapper".equals(propertyType);
    }

    @Override
    public String resolve(StringBuilder objectPreContent, String defName, String propertyName, String propertyType) {
        objectPreContent.append("""
                                    val %sOffset = %sFb.create%sFb(
                                        builder,
                                        %sFb.create%sVector(m.%s),
                                        %sFb.create%sVector(m.%s)
                                    )
                    """.formatted(
                propertyName,
                propertyType,
                propertyType,
                propertyType,
                propertyType,
                propertyName,
                propertyType,
                propertyType,
                propertyName
        ));
        return "%sOffset".formatted(propertyName);
    }

    @Override
    public String resolveVector(StringBuilder objectPreContent, String defName, String propertyName, String propertyType) {
        objectPreContent.append("""
                                val %sOffsets = m.%s.map(p => {
                                    WeightsWrapperFb.createWeightsWrapperFb(
                                        builder,
                                        WeightsWrapperFb.createValueArrVector(m.valueArr),
                                        WeightsWrapperFb.createWeightArrVector(m.weightArr)
                                    )
                                })
                """.formatted(
                    propertyName,
                    propertyName
                ));
        return "%sOffsets".formatted(propertyName);
    }
}
